<template>
  <div class="app-my-message">
    <table-page
      :tableData="tableData"
      :tableColumn="tableColumn"
      :isIndex="false"
      :isSelection="false"
      :total="pages.total"
      :pageSize="pages.pageSize"
      :currentPage="pages.pageNum"
      @sizeChange="handleSizeChange"
      @currentChange="handleCurrentChange"
    >
      <template #handle>
        <el-button type="primary" @click="handleIsReads" v-hasPermi="['CentralControl.MyMessage.SetReaded']">全部标记已读</el-button>
      </template>
      <template slot="content" slot-scope="{ row }">
        <span class="links" @click="toCustomerDetail(row)">{{ row.content }}</span>
      </template>
    </table-page>
  </div>
</template>

<script>
import { getMessageSate, setMessageIsRead } from '@/api/message'
import SearchBar from '@/components/SearchBar'
import TablePage from '@/components/TablePage'
export default {
  name: 'HistoryAudit',
  components: {
    TablePage,
    SearchBar,
  },
  data: function () {
    return {
      queryParams: {},
      tableData: [],
      tableColumn: [
        {
          label: '消息标题',
          prop: 'title',
          type: 'yuanText',
          colors: [
            { color: '#ee3333', value: false },
            { color: 'green', value: true },
          ],
          by: 'isRead',
        },
        {
          label: '消息内容',
          prop: 'content',
          // type: 'linkText',
          render: true,
        },
        {
          label: '创建时间',
          prop: 'creationTime',
        },
      ],
      pages: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
      },
    }
  },
  computed: {
    userId: function () {
      return JSON.parse(this.$store.state.user?.details).id
    },
  },
  created() {
    this.getTableData()
  },
  methods: {
    getTableData() {
      const params = {
        type: [3],
        isDetails: true,
        SkipCount: ((this.pages.pageNum <= 1 ? 1 : this.pages.pageNum) - 1) * this.pages.pageSize,
        MaxResultCount: this.pages.pageSize,
        ...this.queryParams,
      }
      getMessageSate(params).then(res => {
        this.tableData = res.items
        this.pages.total = res.totalCount
      })
    },
    handleIsReads() {
      setMessageIsRead([]).then(res => {
        this.$message.success('已读设置成功')
        this.getTableData()
      })
    },
    handleSizeChange(v) {
      this.pages.pageSize = v
      this.pages.pageNum = 1
      this.getTableData()
    },
    handleCurrentChange(v) {
      this.pages.pageNum = v
      this.getTableData()
    },
    toCustomerDetail(row) {
      let { noticeBusinessType, dataId } = row
      let { CustomerClueId } = JSON.parse(row.dataOther)
      let array = [6, 7, 8, 9]
      let query = {
        noticeBusinessType,
        dataId,
      }
      if (array.includes(noticeBusinessType)) {
        query.dataId = CustomerClueId
      }
      this.$router.push({
        path: '/customer-app/customer',
        query,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.app-my-message {
  .handle-box {
    padding: 20px;
  }
  .links {
    color: #0076ff;
    cursor: pointer;
    &:hover {
      text-decoration: underline;
    }
  }
}
::v-deep .table-page .el-table th:first-child > .cell,
::v-deep .table-page .el-table td:first-child > .cell {
  padding-left: 30px;
}
</style>
